#ifndef _CU_MATH_H_
#define _CU_MATH_H_

#define _USE_MATH_DEFINES 1
#include <math.h>

#pragma warning(disable: 4146) // disable minus operator applied to unsigned type warning

//**********************************************************************************
// common math functions
//**********************************************************************************

template <class T>
SDH_CALL  T min(T a, T b)
{
	return (a > b) ? b : a;
}

template <class T>
SDH_CALL  T max(T a, T b)
{
	return (a < b) ? b : a;
}

template <class T>
SDH_CALL T sqr(T a)
{
	return (a * a);
}

template <class T>
SDH_CALL T abs(T a)
{
	return (a > 0) ? a : -a;
}

template <class T>
SDH_CALL T  clamp(T u, T a, T b) 
{ 
  T r = max(a, u); 
  return min(r, b); 
}

template <class T>
SDH_CALL int sign(T v)
{
  return ( (v > 0) ? 1 : ( v < 0 ? -1 : 0));
}

template <class T>
SDH_CALL T to_radian(T angle)
{
  return (T) M_PI * angle / ((T)180.0f);
}

template <class T>
SDH_CALL T to_angle(T radian)
{
  return radian * ((T)180.0) / M_PI ;
}

template <class T>
SDH_CALL void swap_value(T & a, T & b)
{
  T c = a;
  a = b;
  b = c;
}

#define EPSILON 0.00001f

#endif